<?php
class infoController extends siteController
{
    public function index()
    {
        $aid = intval($_GET['aid']);
        $urltitle = in($_GET['urltitle']);
        if (empty($aid)&&empty($urltitle)) {
            $this->error404();
        }

        //读取基本内容信息
        if(!empty($aid)){
            $info=model('content_info')->info($aid);
        }else if(!empty($urltitle)){
            $info=model('content_info')->info($urltitle,true);
        }else{
            $this->error404();
        }

        if (!is_array($info)||$info['status']==0) {
            $this->error404();
        }

        //读取栏目信息
        $this->category=model('category_list')->info($info['cid']);
        if (!is_array($this->category)){
            $this->error404();
        }
        if($this->category['model']<>APP_NAME){
            $this->error404();
        }

        //判断跳转
        if (!empty($info['url']))
        {
            $link=$this->display(html_out($info['url']),true,false);
			header("HTTP/1.1 301 Moved Permanently");
			header("Location: ".$link."");
			exit;
        }

        //位置导航
        $this->nav=api('default','category_nav',$info['cid']);

        //查询上级栏目信息
        $this->parent_category = model('category_list')->info($this->category['pid']);

        //获取顶级栏目信息
        $this->top_category = model('category_list')->info($this->nav[0]['cid']);

        //读取完整内容信息
        $info=model('content_info')->info_data($info['aid'],$this->category);

        if(empty($info['content'])){
            $info['content']='暂无内容';
        }
        $content=$info['content'];

        //更新访问计数
        api('default','content_views',array('aid'=>$info['aid'],'views'=>$info['views']));
        
        //读取内容替换
        if(!empty($content)){
            $content=api('default','content_replace',$content);
        }
        //自动增加TAG链接
        if(!empty($content)&&$info['taglink']){
            $content=api('default','content_tag_link',array('content'=>$content,'aid'=>$info['aid']));
        }

        //MEDIA信息
        $this->common=api('default','common_media',array('title'=>$info['title'],'keywords'=>$info['keywords'],'description'=>$info['description']));
        
        //内容分页
        $url=model('label_content')->get_aurl($info,true);
        $page = new Page();
        $content = $page->contentPage(html_out($content), "<hr class=\"ke-pagebreak\" />", $url, 10, 4); //文章分页
        $info['content']=$content['content'];
        $this->page=$content['page'];
        
        $this->info=$info;
        //上下篇
        $prev=api('default','content_prev',array('aid'=>$info['aid'],'category'=>$this->category));
        if(!empty($prev)){
            $prev['aurl']=model('label_content')->get_aurl($prev);
        }
        $this->prev=$prev;
        //下一篇
        $next=api('default','content_next',array('aid'=>$info['aid'],'category'=>$this->category));
        if(!empty($next)){
            $next['aurl']=model('label_content')->get_aurl($next);
        }
        $this->next=$next;

        if(empty($info['tpl'])){
        $this->show($this->category['content_tpl']);
        }else{
        $this->show($info['tpl']);
        }

    }

}
